Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added last_updated_at in players search results and player summary #184

Merged
merged 1 commit into from
Aug 25, 2024

Conversation

TeKrop
Copy link
Owner

@TeKrop TeKrop commented Aug 25, 2024

Summary by Sourcery

Introduce a new 'last_updated_at' field in player search results and player summary to track the last update time of player profiles. Enhance the player search API to support ordering by this new field and update relevant test cases to ensure proper functionality.

New Features:

  • Add 'last_updated_at' field to player search results and player summary to indicate the last time a player's profile was updated on Blizzard.

Enhancements:

  • Update the player search API to allow ordering by 'last_updated_at'.

Tests:

  • Update test cases for player career, stats, and summary routes to include checks for the 'last_updated_at' field.

@TeKrop TeKrop added the enhancement New feature or request label Aug 25, 2024
@TeKrop TeKrop self-assigned this Aug 25, 2024
Copy link
Contributor

sourcery-ai bot commented Aug 25, 2024

Reviewer's Guide by Sourcery

This pull request adds a new field 'last_updated_at' to the player search results and player summary. The implementation includes updating models, parsers, handlers, and tests to accommodate this new field. The changes also involve modifying the search functionality to allow ordering by the new 'last_updated_at' field.

File-Level Changes

Change Details Files
Added 'last_updated_at' field to player models
  • Added 'last_updated_at' field to PlayerShort model
  • Added 'last_updated_at' field to PlayerSummary model
  • Updated field descriptions and examples
app/models/players.py
Updated handlers to include 'last_updated_at' in API responses
  • Modified GetPlayerCareerRequestHandler to include LastUpdatedAtParser
  • Updated merge_parsers_data method to include 'last_updated_at' in the summary
app/handlers/get_player_career_request_handler.py
Created LastUpdatedAtParser to extract 'last_updated_at' data
  • Implemented LastUpdatedAtParser class
  • Added method to retrieve 'lastUpdated' value from player data
app/parsers/search_data_parser.py
Updated search functionality to support 'last_updated_at'
  • Modified search_players function to allow ordering by 'last_updated_at'
  • Updated apply_transformations method to include 'last_updated_at' in player data
app/routers/players.py
app/handlers/search_players_request_handler.py
Updated tests to accommodate new 'last_updated_at' field
  • Modified test cases for player career, stats, and summary routes
  • Updated mock responses to include 'last_updated_at' data
  • Adjusted test fixtures to include 'last_updated_at' field
tests/views/test_player_career_route.py
tests/views/test_player_stats_route.py
tests/views/test_player_summary_view.py
tests/parsers/test_player_parser.py
tests/fixtures/json/players/*.json
Updated search data cache functionality
  • Modified update_search_data_cache function to exclude LAST_UPDATED_AT from cache update
  • Added LAST_UPDATED_AT to SearchDataType enum
app/commands/update_search_data_cache.py
app/common/enums.py
Updated search players API result fixture
  • Added 'last_updated_at' field to each player entry in the search results
tests/fixtures/json/search_players/search_players_api_result.json

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

sonarcloud bot commented Aug 25, 2024

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @TeKrop - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a utility function or option to convert the Unix timestamp in last_updated_at to a more human-readable format for improved usability.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.


data_type = SearchDataType.LAST_UPDATED_AT

def retrieve_data_value(self, player_data: dict) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Add error handling for missing 'lastUpdated' key

Consider adding error handling in case the 'lastUpdated' key is missing from the player_data dictionary. You could use a try-except block or the dict.get() method with a default value to make this more robust and prevent potential KeyError exceptions.

Suggested change
def retrieve_data_value(self, player_data: dict) -> int:
def retrieve_data_value(self, player_data: dict) -> int:
return player_data.get("lastUpdated", 0)

@@ -35,7 +35,13 @@ def test_get_player_career(
side_effect=[
# Player HTML page
Mock(status_code=status.HTTP_200_OK, text=player_html_data),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Update test to include last_updated_at parser

The test has been updated to include an additional mock for the last_updated_at parser. However, it would be beneficial to add assertions to verify that the last_updated_at field is correctly included in the response.

            side_effect=[
                Mock(status_code=status.HTTP_200_OK, text=player_html_data),
                Mock(return_value=datetime(2023, 1, 1, tzinfo=timezone.utc)),

@@ -57,7 +57,15 @@ def test_get_player_stats(
overfast_client,
"get",
side_effect=[
# Player HTML page
Mock(status_code=status.HTTP_200_OK, text=player_html_data),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add assertions for last_updated_at in player stats

The test has been updated to include mocks for the last_updated_at parser, but it's important to add assertions to verify that the last_updated_at field is correctly included in the player stats response.

        overfast_client,
        "get",
        side_effect=[
            # Player HTML page
            Mock(status_code=status.HTTP_200_OK, text=player_html_data),
            # Last updated timestamp
            Mock(status_code=status.HTTP_200_OK, text="2023-05-01 12:00:00"),
        ],
    )
    response = client.get(f"/players/{player_id}/stats")
    assert response.status_code == status.HTTP_200_OK
    assert "last_updated_at" in response.json()
    assert response.json()["last_updated_at"] == "2023-05-01 12:00:00"

player_data = player_json_data.copy()
del player_data["summary"]["namecard"]
del player_data["summary"]["last_updated_at"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add test for LastUpdatedAtParser

While the test has been updated to remove the last_updated_at field from the player data, it would be beneficial to add a separate test case for the LastUpdatedAtParser to ensure it correctly parses and returns the last_updated_at value.

@pytest.mark.asyncio
async def test_last_updated_at_parser():
    mock_data = {"summary": {"last_updated_at": "2023-05-01T12:00:00Z"}}
    parser = LastUpdatedAtParser()
    result = await parser.parse(mock_data)
    assert isinstance(result, datetime)
    assert result.isoformat() == "2023-05-01T12:00:00+00:00"

@TeKrop TeKrop merged commit 9325b4f into main Aug 25, 2024
3 checks passed
@TeKrop TeKrop deleted the feature/profile-last-updated-at branch August 25, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant